import sys
import xmlrpclib
import time
import os
import datetime
import decimal

#path='C:\\Users\FClab\\Rb_DFCS_data\\'
path='C:\\Python27\\test.txt'
#Input Menlo Computer IP addr
#server_ip=raw_input("Enter IP address: ")
#fn=raw_input("Enter file name: ")
server_ip='134.154.249.247'
server_url='http://comb:system@'+server_ip+':8123/RPC2'
# Create an object to represent our server.
server = xmlrpclib.ServerProxy(server_url);
###############################################################
#Check whether the server is alive
status=server.hello()
print status
#Check current DDS frequency
result = server.comb.reprate.synth.getFreq()
print "Synthesizer is (Hz):", result
###############################################################
#Print out the lastest data set
timestamp= server.data.last_timestamp()
print "\nTimestamp of most recent data is",timestamp,"\n"

fn=open(path,'a')

###############################################################
#Print channels of interests: reprate.freq and aux0
DataChannels=['offset.freq','reprate.freq','aux0']
data= server.data.query(-1.000,DataChannels)
if (type(data)!=type('str')):
		timestamps=data.keys()
		timestamps.sort()
#print data.items()
#dk=data.keys()
#for ts in timestamps:
	#lts=float(ts)
	#print " %.4f =>" % lts
	#for value in DataChannels:
	#	print "%0.10f " % data[ts][value]
for key, value in data.iteritems():
    temp=value
    #datastr=''
    for key,value in temp.iteritems():
        #datastr=datastr+' '+str(value)
        fn.write(' %s '%(repr(value)))
fn.write('\n')
fn.close()        
